<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>

<?php  
	include("view.css.php");
	include("view.js.php");
?> 
<!-- Slider -->
<?php if($showAsSlider == true){	
	$ih = Loader::helper('image');
	$th = Loader::helper('text');
	$uh = Loader::helper('url');
	$slideNum = 0;
	$slideIndex = 0;			
	echo "<div class='project_gallery'>";
		echo "<div id='main'><div id='pages'>";
		foreach($imagesForFullView as $imgInfo) {
			$f = File::getByID($imgInfo['fID']);
			$thumb = $ih->getThumbnail($f, $width, $height);
			$thumbSmall = $ih->getThumbnail($f, $maxThumbnailWidth, $maxThumbnailHeight);
			echo '<img width="' . $thumb->width . '" height="' . $thumb->height . '" src="'.$thumb->src.'" slideIndex="'.$slideIndex++.'" alt="'.$thumbSmall->src.'"/>';
		}		
		echo '</div></div>';
		echo '<script type="text/javascript">
				$(function () {
					$("#pages").cycle({ 
						fx:     "'.$controller->getTransitionFX($transitionFX).'", 
						speed:   500, 
						timeout: 0, 
						pager:  "#nav",
						// callback fn that creates a thumbnail to use as pager anchor 
						pagerAnchorBuilder: function(idx, slide) {
						   return "<li><a href=\'#\'><img src=\'" + $(slide).attr("alt") + "\'/></a></li>"; 
						} 						        
					});
					$(".scrollable").scrollable({vertical: true, mousewheel: true, next: ".navi_down", prev: ".navi_up"});
				});
			</script>';

		echo '<div id="main_navi">';
		echo '<a class="navi_up" href="#"></a>';
		echo '<div class="scrollable">';
		echo '<ul id="nav" class="items">';							
		echo '</ul>';
		echo '</div>';
		echo '<a class="navi_down" href="#"></a>';
		echo '</div>';			
	echo '</div>';
}else{
?>
<div class="AmiantImageGalleryBlock">
	<?php $displayThumb = '';
		if($showAsThumbnails == true && count($imagesForThumbnails) == true && $enableZoomMode): $displayThumb = 'display: none; visibility: hidden;';?>		
		<h2><a href="javascript:void(0)" onclick="javascript:$('a.zoomModeImage<?php echo $bID;?>:first').click();return false;"><?php echo $title;?></a></h2>
	<?php endif;?>
	<div class="AmiantImageGalleryBlock<?php echo $bID?> AmiantImageGallery<?php echo $bID?>" style="<?php echo $displayThumb; ?>">
		<?php if($paginator && strlen($paginator->getPages())>0) {
				if (($showAsThumbnails == true) && (!isset($_REQUEST['aigid'.$bID]))) {
		?>
					 <div class="AmiantImageGalleryBlockControlBar<?php   echo $bID?>">
						<div  class="ig_pagination" style="clear: both;">
							<div class="ig_pagination_controls">
								<span class="ig_pageLeft"><?php   echo $paginator->getPrevious()?></span>
								<span class="ig_pager"><?php   echo $paginator->getPages()?></span>
								<span class="ig_pageRight"><?php   echo $paginator->getNext()?></span>
							</div>
						</div>
					</div>
		<?php    		} 
			}
		?>		
		<!-- Thumbnail -->		
		<?php	
		if (($showAsThumbnails == true) && (!isset($_REQUEST['aigid'.$bID]))) {
			$ih = Loader::helper('image');
			$th = Loader::helper('text');
			$uh = Loader::helper('url');
			
			if (isset($_REQUEST['aig_p'.$bID])) {
				$slideNum = $maxThumbnailsPerPage * (intval($_REQUEST['aig_p'.$bID]) - 1);
			} else {
				$slideNum = 0;
			}
			
			foreach($imagesForThumbnails as $imgInfo) {
				$f = File::getByID($imgInfo['fID']);
				
				$thumb = $ih->getThumbnail($f, $maxThumbnailWidth, $maxThumbnailHeight);
				
				echo '<div id="AmiantImageGalleryThumbnailContainerWrapper'.$imgInfo['fID'].$bID.'" class="AmiantImageGalleryThumbnailContainerWrapper'.$bID.'">';
				echo '<div id="AmiantImageGalleryThumbnailContainer'.$imgInfo['fID'].$bID.'" class="AmiantImageGalleryThumbnailContainer'.$bID.' AmiantImageGalleryThumbnailContainerLoading'.$bID.'" >';
				
				if($imgInfo['url']) {
					echo '<a id="AmiantImageGalleryThumbnailLink'.$imgInfo['fID'].$bID.'" class="AmiantImageGalleryThumbnailLink" href="'.$imgInfo['url'].'">';
				} else {
					$imgTitle = "";
					if ($enableZoomMode) {
						$fullsizeImg = $ih->getThumbnail($f, $zoomModeMaxWidth, $zoomModeMaxHeight);
						$url = $fullsizeImg->src;
						if ($zoomModeDisplayInformation && $zoomModeDisplayCaption) $imgTitle = $imgInfo['caption'];
					} else {
						$url = $uh->setVariable(array("aigid".$bID => $slideNum), false, "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
					}
					echo '<a id="AmiantImageGalleryThumbnailLink'.$imgInfo['fID'].$bID.'" class="AmiantImageGalleryThumbnailLink zoomModeImage'.$bID.'" rel="aigGroup'.$bID.'" href="'.$url.'" title="'.$imgTitle.'">';
				}
				echo '</a>';
				echo '</div>';
				if($displayThumbnailBubblePopup) {
					if (($displayThumbnailCaption) && (!$imgInfo['caption'])) $displayCaption = false; else $displayCaption = true;
					if ((!$displayCaption) && (($displayThumbnailFileName) || ($displayThumbnailFileType) || ($displayThumbnailFileSize) || ($displayThumbnailDownloadLink))) $withoutCaption = true; else $withoutCaption = false;
					if (($displayCaption) && ((!$displayThumbnailFileName) && (!$displayThumbnailFileType) && (!$displayThumbnailFileSize) && (!$displayThumbnailDownloadLink))) $onlyCaption = true; else $onlyCaption = false;
					
					
					if (($displayCaption) || ($displayThumbnailFileName) || ($displayThumbnailFileType) || ($displayThumbnailFileSize) || ($displayThumbnailDownloadLink)) {
						echo '	<div>
							<table class="AmiantImageGalleryBlockPopup" style="width: '.intval($maxThumbnailWidth * 2).'px;">
								<tbody>
									<tr>
										<td class="top_left"></td>
										<td class="top"></td>
										<td class="top_right"></td>
									</tr>
									<tr>
										<td class="left"></td>
										<td class="center">';
											if ($displayCaption) echo $imgInfo['caption'];
											if ($withoutCaption) echo '<div class="AmiantImageGalleryBlockFileInfoNoCaption">';
											if (($displayCaption) && (!$withoutCaption) && (!$onlyCaption)) echo '<div class="AmiantImageGalleryBlockFileInfo">';
											if ($displayThumbnailFileName) echo t('Name').': '.$th->shorten($imgInfo['fileName'], 20, '...').'<br />';
											if ($displayThumbnailFileType) echo t('Type').': '.$imgInfo['type'].'<br />';
											if ($displayThumbnailFileSize) echo t('Size').': '.$imgInfo['size'].'<br />';
											if ($displayThumbnailDownloadLink) echo	'<a href="/index.php/download_file/view/'.$imgInfo['fID'].'/">'.t('Download').'</a>';
											if ((!$onlyCaption) || ($withoutCaption)) echo '</div>';
						echo '					
										</td>
										<td class="right"></td>
									</tr>
									<tr>
										<td class="bottom_left"></td>
										<td class="bottom"></td>
										<td class="bottom_right"></td>
									</tr>
								</tbody>
							</table>
							</div>
						';
					}
				}
				echo '</div> ';
				echo '
					<script type="text/javascript">
						$(function () {
							AmiantImageGalleryBlockLoadImage'.$bID.'("'.$thumb->src.'", "AmiantImageGalleryThumbnail'.$bID.'", "'.intval($thumb->height / -2).'", "'.$imgInfo['caption'].'", "'.$imgInfo['caption'].'", "AmiantImageGalleryThumbnailContainer'.$imgInfo['fID'].$bID.'", "AmiantImageGalleryThumbnailLink'.$imgInfo['fID'].$bID.'");
		    			});
					</script>
				';
				$slideNum++;
			}
			if($displayThumbnailBubblePopup) {
				echo '
					<script type="text/javascript">
						AmiantImageGalleryBlockCreatePopups'.$bID.'();
					</script>
				';
			}
		} else if ((isset($_REQUEST['aigid'.$bID])) || (!$showAsThumbnails)) {
			$th = Loader::helper('text');
			
			$c = Page::getCurrentPage();
			if ($c->isEditMode()) {
			?>
			<div class="ccm-edit-mode-disabled-item" style="width:<?php   echo $width?>px; height:<?php   echo $height?>px;">
				<div style="padding:8px 0px; padding-top: <?php   echo round($height/2)-10?>px;"><?php   echo t('Content disabled in Edit Mode.'); ?></div>
			</div>
			<!-- End Thumbnail -->
			<?php  
			} else {
				$ih = Loader::helper('image');
				
				if (!$showAsThumbnails)	$startingSlide = 0;
				else $startingSlide = intval($_REQUEST['aigid'.$bID]);
				
				$slideIndex = 0;			
			?>
			<?php if($autoSlide==0):?>
			<div class="AmiantImageGalleryBlockControlBar<?php   echo $bID?>">
				<div class="AmiantImageGallerySlideControllsWrapper<?php   echo $bID?>" style="clear: both;">
					<span id="AmiantImageGalleryImagesLoadingWaiter<?php   echo $bID?>"><img src="<?php   echo $this->getBlockUrl(); ?>/images/ajax-loader-small.gif" width="16" height="16" alt="" /></span>
					<span id="AmiantImageGalleryImagesLoaded<?php   echo $bID?>" style="display: none;">Loaded ?</span>
					<span id="AmiantImageGalleryImageIndex<?php   echo $bID?>">Image X of Y</span> |
					<span id="AmiantImageGallerySlideControllPrev<?php   echo $bID?>" class="AmiantImageGallerySlideControllPrev<?php   echo $bID?>">&laquo; <?php   echo t('Previous'); ?></span>
					|
					<span id="AmiantImageGallerySlideControllNext<?php   echo $bID?>" class="AmiantImageGallerySlideControllNext<?php   echo $bID?>"><?php   echo t('Next'); ?> &raquo;</span>
				</div>
			</div>
			<?php endif;?>
			<?php  
				echo '<div id="AmiantImageGallerySlidesWrapper'.$bID.'" class="AmiantImageGallerySlidesWrapper'.$bID.'">';
				foreach($imagesForFullView as $imgInfo) {
					if (($displayThumbnailCaption) && (!$imgInfo['caption'])) $displayCaption = false; else $displayCaption = true;
					if ($displaySlideInformation) {
						$displaySlideInformation = false;
						if ($displayCaption) $displaySlideInformation = true;
						if ($displaySlideFileName) $displaySlideInformation = true;
						if ($displaySlideFileType) $displaySlideInformation = true;
						if ($displaySlideFileSize) $displaySlideInformation = true;
						if ($displaySlideDownloadLink) $displaySlideInformation = true;
					}
					
					$slideIndex++;
					
					$f = File::getByID($imgInfo['fID']);
					
					$thumb = $ih->getThumbnail($f, $width, $height);
					
					echo '<div class="AmiantImageGallerySlide'.$bID.'" imgsrc="'.$thumb->src.'" slideIndex="'.$slideIndex.'">';
					
					if ($displaySlideInformation) {
						echo '<div class="AmiantImageGallerySlideInfo'.$bID.'">';
						
						if ($displayCaption) echo '<h2>'.$imgInfo['caption'].'</h2>';
						if ($displaySlideFileName) echo '<p>'.t('Name').': '.$th->shorten($imgInfo['fileName'], 20, '...').'</p>';
						if ($displaySlideFileType) echo '<p>'.t('Type').': '.$imgInfo['type'].'</p>';
						if ($displaySlideFileSize) echo '<p>'.t('Size').': '.$imgInfo['size'].'</p>';
						if ($displaySlideDownloadLink) echo	'<p><a href="/index.php/download_file/view/'.$imgInfo['fID'].'/">'.t('Download').'</a></p>';
						
						echo '</div>';
					}
					
					echo '</div>';
					
				}
				
				echo '</div>';
				
				echo '
					<script type="text/javascript">
						$(function () {
							AmiantImageGalleryBlockCalculateImagesCount'.$bID.'();
							AmiantImageGalleryBlockStartSlideshow'.$bID.'('.$startingSlide.');
						});
					</script>
				';
			}
		}
		?>
		
	</div>
	<div style="clear: both;"></div>
</div>
<?php }?>